<template>
  <div>
  <el-table
    :data="testData"
    stripe
    style="width: 100%"
    @row-click="openDetails">
    <el-table-column
      prop="date"
      label="日期"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="设备">
    </el-table-column>
    <el-table-column
      prop="id"
      label="地址">
    </el-table-column>
  </el-table>
  <el-dialog
    title="提示"
    :visible.sync="chartDialog"
    width="30%"
    :before-close="handleClose">
    <span>{{thisDevice}}</span>
    <span slot="footer" class="dialog-footer">
    <el-button @click="chartDialog = false">取 消</el-button>
    <el-button type="primary" @click="chartDialog = false">确 定</el-button>
  </span>
  </el-dialog>
  </div>
</template>

<script>
import { getDevices } from '@/api/device'
import { getLineId } from '@/utils/line'

export default {
  data() {
    return {
      testData: [{
        date: '2016-05-02',
        name: '王小虎',
        id: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        id: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        id: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        id: '上海市普陀区金沙江路 1516 弄'
      }],
      chartDialog: false,
      thisDevice: '',
      deviceList: []
    }
  },
  methods: {
    openDetails(row) {
      this.thisDevice = row.id
      this.chartDialog = true
    },
    getDevicesList() {
      getDevices(getLineId()).then(response => {
        this.deviceList = response.data
      })
    }
  },
  mounted() {
    this.getDevicesList()
  }
}
</script>
